﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 引用类型或值类型的比较
{
    class Person
    {
        private string _name;
        private int _age;

        public Person(string name, int age)
        {
            _name = name;
            _age = age;
        }

        public override bool Equals(object obj)
        {
            return obj is Person person &&
                   _name == person._name &&
                   _age == person._age;
        }

        public override string ToString()
        {
            return $"name={_name},age={_age}";
        }
    }

    internal class Program
    {
        static void Main(string[] args)
        {
            //int a = 10;
            //int b = 10;
            //Console.WriteLine(a == b);//true

            //bool b1 = true;
            //bool b2 = true;
            //Console.WriteLine(b1 == b2);//true
            //Console.ReadKey();

            //Person person = new Person("张三", 18);
            //Person person1 = new Person("张三", 18);
            //Console.WriteLine(ReferenceEquals(person, person1));//false

            //Person person = new Person("张三", 18);
            //Person person1 = new Person("张三", 18);
            //Console.WriteLine(person.Equals(person1));//true

            //string s1 = "acd";
            //string s2 = "acd";
            //Console.WriteLine(s1 == s2);//true
            //Console.WriteLine(ReferenceEquals(s1, s2));//true
            //Console.WriteLine(s1.Equals(s2));//true

            Person person = new Person("张三", 18);
            Console.WriteLine(person);//name=张三,age=18
        }
    }
}
